package com.crealth;

import java.util.List;
import org.apache.log4j.Logger;
import com.crealth.db.MonthPlanDb;
import com.crealth.db.UserDb;
import com.crealth.manager.MybatisManager;
import com.crealth.memcached.MemcachedMgr;
import com.crealth.model.MonthPlanModel;
import com.crealth.utils.Utils;

public class SalesmanPlanMain {
	private static Logger logger = Logger.getLogger("running_log");
	private static Logger errorLog = Logger.getLogger("error_log");
	
	
	
	public static void main(String[] args) {
		try {
			String osName = Utils.getOSName();
			logger.info("OS: " + osName);			
			Config.initConfig();
			MybatisManager.initSessionFactory();			
		} catch (Exception e) {
			errorLog.error("init config error", e);
			System.exit(0);
		}		
		
		MemcachedMgr.initMemcached();
		List<Integer> salesmanls = UserDb.selectAllSalesManIDs();
		for (Integer userID : salesmanls) {
			MonthPlanModel monthPlan = MonthPlanDb.selectUserMonthPlan(userID);
			if (monthPlan == null) {
				monthPlan = new MonthPlanModel();
				monthPlan.setUserID(userID);
				monthPlan.setMonth(0);
				MonthPlanDb.insertMonthPlan(monthPlan);
			}
		}
		
		
		logger.info("----      finished    ------------");
		
	}	
	
	
}
